
$(function() {
    validateRule();
    $(".i-checks").iCheck({checkboxClass:"icheckbox_square-green-login"});

});
$.validator.setDefaults({
    submitHandler: function() {
        login();
    }
});

function login() {
	$.modal.loading($("#btnSubmit").data("loading"));
	var username = $("input[name='username']").val().trim();
    var password = $("input[name='password']").val().trim();
    var rememberMe = $("input[name='rememberme']").is(':checked');
    var json = {
        "username" : username,
        "password" : password,
        "rememberMe" : rememberMe
    };
    console.log(json);
    $.ajax({
        type: "post",
        url: "/user/login",
        dataType:"json",
        contentType:"application/json",
        data: JSON.stringify(json),
        success: function(r) {
            if (r.code == 200){
                location.href ='/index';
            } else{
            	$.modal.closeLoading();
            	$('.imgcode').click();
            	$.modal.msg(r.message);
            }
        }
    });
}
function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules: {
            username: {
                required: true
            },
            password: {
                required: true
            }
        },
        messages: {
            username: {
                required: icon + "请输入您的用户名",
            },
            password: {
                required: icon + "请输入您的密码",
            }
        }
    })
}
